<?php
namespace App\Http\Controllers\ApiWx;

use App\DBs\VideoDB;
use Illuminate\Http\Request;

class VideoController extends BaseController
{
    //视频

    protected $db;

    public function __construct()
    {
        parent::__construct();
        $this->db = new VideoDB();
    }

    /**
     * 果干一个
     */
    public function getOne(Request $request)
    {
        $wx = $request->post('wx','');
        $id = $request->post('id',0);
        $oper = $request->post('oper',0); //1上拉，2下拉，
        if (!in_array($oper,[1,2])) {
            return $this->toWxJson(-2);
        }
        $resDb = $this->db->getOneByOper($wx,$id,$oper,1);
        if ($resDb['code']!=0) {
            return $this->toWxJson(-3);
        }
        $items = $resDb['data'];
        return $this->toWxJson(0,$items);
    }

    /**
     * 农产品一个
     */
    public function getSideOne(Request $request)
    {
        $wx = $request->post('wx','');
        $id = $request->post('id',0);
        $oper = $request->post('oper',0); //1上拉，2下拉，
        if (!in_array($oper,[1,2])) {
            return $this->toWxJson(-2);
        }
        $resDb = $this->db->getOneByOper($wx,$id,$oper,2);
        if ($resDb['code']!=0) {
            return $this->toWxJson(-3);
        }
        $items = $resDb['data'];
        return $this->toWxJson(0,$items);
    }

    /**
     * 点赞设置
     */
    public function setPraise(Request $request)
    {
        $wx = $request->post('wx','');
        $vid = $request->post('id',0);
        if (!$wx) {
            return $this->toWxJson(-4);
        }
        if (!$vid) {
            return $this->toWxJson(-2);
        }
        $resZan = $this->db->getPraiseOne($wx,$vid);
        if ($resZan) {
            $resDb = $this->db->setPraiseDel($wx,$vid);
        } else {
            $resDb = $this->db->setPraiseAdd($wx,$vid);
        }
        if (!$resDb) {
            return $this->toWxJson(-500);
        }
        return $this->toWxJson(0);
    }
}